package cn.chinaunicom.sdsi.activiti.example.controller;

import java.util.HashMap;
import java.util.Map;

import org.activiti.engine.repository.Deployment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import cn.chinaunicom.sdsi.activiti.example.service.ActivtiDemoService;

@RestController
public class ActivitDemoController {

	@Autowired
	private ActivtiDemoService activtiDemoService;
	
	@PostMapping(value="startProcess")
	public void startProcess(@RequestParam String processDefinitionKey, @RequestParam String businessKey,@RequestParam String user) {
		Map<String, Object> variables = new HashMap<>();
		variables.put("assignee", user);
		activtiDemoService.startProcess(processDefinitionKey, businessKey, variables);
	}
	
	@PostMapping(value="deployProcess")
	public Deployment deployProcess(@RequestParam(value = "file", required = false) MultipartFile file,@RequestParam String key,@RequestParam String name, @RequestParam String tenantId) {
		return activtiDemoService.deployProcess(file, key, name, tenantId);
	}
	
	@PostMapping(value="taskComplate")
	public void taskComplate(@RequestParam String taskId, String userId){
		activtiDemoService.taskComplate(taskId, userId);
	}
	
}
